"""主题管理器"""
from PyQt5.QtCore import QSettings
from qt_material import apply_stylesheet

"""主题管理器"""

class theme_control:
    """
    主题管理器 和 字体颜色管理器
    """
    @staticmethod
    def theme_set_dark(app):
        """设置主题为暗色"""
        apply_stylesheet(app, theme='dark_teal.xml')

    @staticmethod
    def theme_set_light(app):
        """设置主题为亮色"""
        apply_stylesheet(app, theme='light_teal.xml')

    @staticmethod
    def theme_load_theme(app):
        """加载主题"""
        # 加载上次保存的主题
        settings = QSettings('Public Tool', 'Themes')
        last_theme = settings.value('LastTheme', 'light')  # 默认为'light'
        if last_theme == 'dark':
            theme_control.theme_set_dark(app)
        else:
            theme_control.theme_set_light(app)

    @staticmethod
    def theme_save_theme(theme_name):
        """保存主题"""
        settings = QSettings('Public Tool', 'Themes')
        settings.setValue('LastTheme', theme_name)

    @staticmethod
    def theme_load_color():
        """加载颜色"""
        settings = QSettings("Public Tool", "ColorSettings")
        saved_color = settings.value("selected_color")

        if saved_color and isinstance(saved_color, tuple) and len(saved_color) == 3 and all(
                isinstance(i, int) and 0 <= i <= 255 for i in saved_color):
            return saved_color

    @staticmethod
    def theme_save_color(rgb_tuple):
        """保存颜色"""
        settings = QSettings("Public Tool", "ColorSettings")
        settings.setValue("selected_color", rgb_tuple)


